﻿Public Class GadgetSetForm

    Private Sub GadgetSetForm_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        Dim path As String = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\Gadget Creator\tmp\gadget.xml"
        Try
            If System.IO.File.Exists(path) = True Then
                Dim xmlreader As System.Xml.XmlDocument
                xmlreader = New System.Xml.XmlDocument()
                xmlreader.Load(path)
                Dim name As String = xmlreader.SelectSingleNode("//name").InnerText
                TextBox1.Text = name
                Dim version As String = xmlreader.SelectSingleNode("//version").InnerText
                TextBox2.Text = version
                Dim author As String = xmlreader.SelectSingleNode("//copyright").InnerText
                TextBox3.Text = author
                Dim description As String = xmlreader.SelectSingleNode("//description").InnerText
                TextBox4.Text = description
            Else
                Dim xmlwriter As New System.IO.StreamWriter(path)
                xmlwriter.Write(My.Resources.xmldefault)
                xmlwriter.Close()
            End If
        Catch ex As Exception
            MsgBox(ex.Message, 16, "Error")
        End Try
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim path As String = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\Gadget Creator\tmp\gadget.xml"
            Dim modify As New System.Xml.XmlDocument()
            modify.Load(path)
            Dim name As Xml.XmlNode = modify.SelectSingleNode("//name")
            name.InnerText = TextBox1.Text
            Dim version As Xml.XmlNode = modify.SelectSingleNode("//version")
            version.InnerText = TextBox2.Text
            Dim copyright As Xml.XmlNode = modify.SelectSingleNode("//copyright")
            copyright.InnerText = TextBox3.Text
            Dim description As Xml.XmlNode = modify.SelectSingleNode("//description")
            description.InnerText = TextBox4.Text
            modify.Save(path)
            Me.Close()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

End Class